home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 103 / CD-ROM 103.iso / edu / martianwin / src / file.c < prev    next >
Encoding:
Text File  |  2003-08-11  |  2.9 KB  |  116 lines

  1. void stop_music();
  2. void init_menu()
  3. {
  4.     menuback=T_LoadT8(DATADIR "/gfx/menuback.T8");
  5.     menu_font_a=T_LoadT8(DATADIR "/fonts/menu_a.T8");
  6.     menu_font_i=T_LoadT8(DATADIR "/fonts/menu_i.T8");
  7.     SDL_SetColorKey(menu_font_a, SDL_SRCCOLORKEY, SDL_MapRGB(menu_font_a->format,0,255,0));
  8.     SDL_SetColorKey(menu_font_i, SDL_SRCCOLORKEY, SDL_MapRGB(menu_font_i->format,0,255,0));
  9.     option_sound=Mix_LoadWAV(DATADIR "/sounds/option.wav");
  10. }
  11.  
  12. void close_menu()
  13. {
  14.     SDL_FreeSurface(menu_font_a);
  15.     SDL_FreeSurface(menu_font_i);
  16.     SDL_FreeSurface(menuback);
  17.     Mix_FreeChunk(option_sound);
  18. }
  19.  
  20. void init_game()
  21. {
  22.     touch=Mix_LoadWAV(DATADIR "/sounds/touch.wav");
  23.     match=Mix_LoadWAV(DATADIR "/sounds/match.wav");
  24.     nomatch=Mix_LoadWAV(DATADIR "/sounds/nomatch.wav");
  25.     combo_sound=Mix_LoadWAV(DATADIR "/sounds/combo.wav");
  26.     music=Mix_LoadMUS(DATADIR "/music/ingame.s3m");
  27.     Schips=T_LoadT8(DATADIR "/gfx/chips.T8");
  28.     SDL_SetColorKey(Schips, SDL_SRCCOLORKEY, SDL_MapRGB(Schips->format,0,255,0));
  29.     scorefont=T_LoadT8(DATADIR "/fonts/score.T8");
  30.     bonusfont=T_LoadT8(DATADIR "/fonts/bonus.T8");
  31.     SDL_SetColorKey(bonusfont, SDL_SRCCOLORKEY, SDL_MapRGB(bonusfont->format,0,255,0));
  32.  
  33.     Mix_Volume(1,48);
  34.     Mix_Volume(2,48);
  35.     Mix_Volume(3,48);
  36.     Mix_Volume(4,128);
  37.     gametime=0;
  38.     score=0;
  39.     combo=0;
  40.  
  41.  
  42. }
  43.  
  44. void close_game()
  45. {
  46.     SDL_FreeSurface(Schips);
  47.     SDL_FreeSurface(scorefont);
  48.     SDL_FreeSurface(bonusfont);
  49.     Mix_FreeChunk(touch);
  50.     Mix_FreeChunk(match);
  51.     Mix_FreeChunk(nomatch);
  52.     Mix_FreeChunk(combo_sound);
  53.     stop_music();
  54.  
  55.     Mix_Volume(-1,128);
  56. }
  57.  
  58. void load_hiscoredata()
  59. {
  60. //    LoadT8(&background,DATADIR "/Tgfx/gameover.T8");
  61.     scorefont2=T_LoadT8(DATADIR "/fonts/score2.T8");
  62.     SDL_SetColorKey(scorefont2, SDL_SRCCOLORKEY,SDL_MapRGB(scorefont2->format,0,255,0));
  63.     FILE *file = fopen(SCOREDIR "/data/scores.dat","rb");
  64.     for(int a=0; a < 10; a++)
  65.     {
  66.     for(int b=0; b < 10; b++)
  67.     {
  68.         scorename[a][b]=getc(file);
  69.     }
  70.         int lobyte,hibyte,vhibyte;
  71.         hibyte=getc(file);
  72.         lobyte=getc(file);
  73.         scoretime[a]=(hibyte*256)+lobyte;
  74.         vhibyte=getc(file);
  75.         hibyte=getc(file);
  76.         lobyte=getc(file);
  77.         scorescore[a]=(vhibyte*65536)+(hibyte*256)+lobyte;
  78.     }
  79.     fclose(file);
  80. }
  81.  
  82. void unload_hiscoredata()
  83. {
  84.     SDL_FreeSurface(scorefont2);
  85. }
  86.  
  87. void save_hiscoredata()
  88. {
  89.     FILE *file = fopen(SCOREDIR "/data/scores.dat","rb+");
  90.  
  91.     int a, b;
  92.     for(a=0;a<10;a++)
  93.     {    
  94.         for(b=0;b<10;b++)
  95.     {
  96.         putc(scorename[a][b],file);
  97.     }
  98.  
  99.         int lobyte,hibyte,vhibyte;
  100.  
  101.         hibyte=int(scoretime[a]/256);
  102.         lobyte=int(scoretime[a]-(hibyte+256));
  103.         putc(hibyte,file);
  104.         putc(lobyte,file);
  105.  
  106.         vhibyte=int(scorescore[a]/65536);
  107.         hibyte=int((scorescore[a] - (scorescore[a]/65536))/256);
  108.         lobyte=int(scorescore[a] - (vhibyte*65536 + hibyte*256));
  109.  
  110.     putc(vhibyte,file);
  111.     putc(hibyte,file);
  112.     putc(lobyte,file);
  113.     }
  114.     fclose(file);
  115. }
  116.